package com.yuan.java.aliyunapi;


import org.junit.Test;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;


/**
 * Created by yeg on 2017/9/12.
 * https://market.aliyun.com/data
 */
public class TestAlibaba {

    @Test
    public void maisn() throws Exception {
        PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
        Resource resource = pathMatchingResourcePatternResolver.getResource("classpath:1.png");
        EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");
        ShowapiRequest req = new ShowapiRequest("http://ali-checkcode.showapi.com/checkcode", "3c2c147565384f7cb8bcb1c071141eb5");
        byte img[] = WebUtils.readByteFromStream(encodedResource.getInputStream());
        String base64string = new String(Base64.encode(img));
        byte b[] = req.addTextPara("typeId", "3040")
                .addTextPara("convert_to_jpg", "1")
                .addTextPara("img_base64", base64string)
                .postAsByte();
        String res = new String(b, "utf-8");
        System.out.println(res);
    }
}
